package Cinema.Tests;

import java.util.List;

import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.NodeDetail;
import org.w3c.dom.Document;

public class XmlBackupTest {
	
	/**
	 * returns if two docs are similar
	 * @param document1
	 * @param document2
	 * @return true or false
	 */
	public static boolean isDocumentsSimilar(Document document1,Document document2){
		Diff diff = new Diff(document1, document2);
		return diff.similar();
	}
	
	/**
	 * return list of differences between two docs
	 * @param document1
	 * @param document2
	 * @return List of differences
	 */
	@SuppressWarnings("unchecked")
	public static List<Difference> getDifferences(Document document1,Document document2){
		Diff diff = new Diff(document1, document2);
		DetailedDiff detailedDiff = new DetailedDiff(diff);
		return detailedDiff.getAllDifferences();
	}
	
	/**
	 * Neutral help function for debugging
	 * put breakpoint in marked line and run it in case of differences between tested docs
	 * @param document1
	 * @param document2
	 */
	@SuppressWarnings("unused")
	public static void iterateOverDifferences(Document document1,Document document2){
		List<Difference> diffList = getDifferences(document1, document2);
		for (Difference difference : diffList) {
			String discription = difference.getDescription();
			NodeDetail detail1 =  difference.getControlNodeDetail();
			NodeDetail detail2 = difference.getTestNodeDetail();
			discription.toString();//put your breakpoint in this line
		}
	}
	
}
